# Makefile for Checkers

CXX = g++
UNAME := $(shell uname)

ifeq ($(UNAME), Linux)
# Linux
LIBCHECKERS = libcheckers.so
else
ifeq ($(UNAME), Darwin)
# Mac
LIBCHECKERS = libcheckers.dylib
else
# Windows
LIBCHECKERS = libcheckers.dll
endif
endif

.PHONY = all board clean

all: Checkers.o $(LIBCHECKERS)

board:
	cd ../board; make

Checkers.o:
	$(CXX) -fPIC -Wall -c -g -O0 -lboard -L../board -o $@ Checkers.cpp

libcheckers.so:
	rm -f $@.1.0.0 $@ $@.1 $@.1.0
	$(CXX) -shared -Wl,-soname,$@.1 -o $@.1.0.0 Checkers.o
	ln -s $@.1.0.0 $@.1.0
	ln -s $@.1.0 $@.1
	ln -s $@.1 $@

libcheckers.dylib:
	$(CXX) -dynamiclib -o $@ Checkers.o

libcheckers.dll:
	$(CXX) -shared -o $@ Checkers.o

test:
ifeq ($(UNAME), Linux)
# Linux
	$(CXX) -L. -lcheckers -L../board -lboard -o $@ test.cpp
else
ifeq ($(UNAME), Darwin)
# Mac
	$(CXX) -L. -lcheckers -L../board -lboard -o $@ test.cpp
else
# Windows
	$(CXX) -L. -lcheckers -L../board -lboard -o $@.exe test.cpp
endif
endif

clean:
	rm -vf test test.exe libcheckers.so* libcheckers.d* *.o
